package com.hxn.wxshake.web;

import com.hxn.wxshake.cache.TimeTest;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;

/**
 * @ClassName IndexPage
 * @Description 一些主要的页面跳转
 * @Author hxn
 * @Date 2019/7/24 13:50
 * @Version 1.0
 **/
@Controller
public class IndexPage {

    /**
     * @return String
     * @Author hxn
     * @Description 等待页的跳转
     * @Param
     **/
    @GetMapping("/index")
    public String index(HttpServletResponse response, String username, String openId,String gender) throws UnsupportedEncodingException {
        Cookie usernameCookie = new Cookie("username",  URLEncoder.encode(URLDecoder.decode(username, "UTF-8"), "UTF-8"));
        Cookie openIdCookie = new Cookie("openId", openId);
        Cookie activityLengthCookie = new Cookie("activityLength", String.valueOf(TimeTest.getActivityLength()));
        Cookie genderCookie = new Cookie("gender",gender);
        response.addCookie(usernameCookie);
        response.addCookie(openIdCookie);
        response.addCookie(activityLengthCookie);
        response.addCookie(genderCookie);
        return "index";
    }

    /**
     * @return String
     * @Author hxn
     * @Description 后台主页面跳转（二维码页面）
     * @Param
     **/
    @GetMapping("/manage")
    public String manage() {
        return "manage" ;
    }

    /**
     * @return String
     * @Author hxn
     * @Description 后台参数配置页面跳转
     * @Param
     **/
    @GetMapping("/time")
    public String time() {
        return "time" ;
    }

    /**
     * @return String
     * @Author hxn
     * @Description 结果页面跳转
     * @Param
     **/
    @GetMapping("/result")
    public String result() {
        return "result" ;
    }

    /**
     * @return String
     * @Author hxn
     * @Description 摇一摇正式活动的页面的跳转
     * @Param
     **/
    @GetMapping("/activity")
    public String activity() {
        return "activity" ;
    }

    /**
     * @Author hxn
     * @Description 跳转到结果页面的过渡页面
     * @Param
     **/
    @GetMapping("/pagejump")
    public String pagejump(){return "pagejump";}
}
